package com.xw.contraller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xw.mapper.MapperPlus;
import com.xw.mapper.MapperPlus02;
import com.xw.pojo.User02;
import com.xw.pojo.User04;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class Controller {
@Autowired
 private MapperPlus mapperPlus;

@Autowired
private MapperPlus02 mapperPlus02;

@GetMapping("selcetAll")
    public Object  selcetAll(){
        List<User02> list= mapperPlus.selectList(null);
        return list;
    }

//根据条件删除
 @GetMapping("delet")
    public  void  delet(int id){
        HashMap hashMap = new HashMap();
        hashMap.put("id",id);
//        hashMap.put("age",8);   多条件
        int i = mapperPlus.deleteByMap(hashMap);

    }


    //mybatisplus分页插件mapp层加强分页查询
    @GetMapping("selcet01")
    public  Object  selcet01(){
        Page<User02> page = new Page<>(1,3);
        mapperPlus.selectPage(page, null);

        List<User02> records = page.getRecords();
        return records;
    }

    @GetMapping("wrapper")
    public  Object  wrapper(){
        QueryWrapper<User04> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("id",8,16).like("age",20).orderByAsc("id");
        List<User04> rs = mapperPlus02.selectList(queryWrapper);
        return rs;
    }


    @GetMapping("wrapper2")
    public  Object  wrapper2(){
        User04 user04 = new User04();

        user04.setAge(2133);
        user04.setId(123);
        user04.setName("xiaowu");
        int rs = mapperPlus02.insert(user04);
        return rs;
    }

    @GetMapping("index")
    public  String index(){
       return  "index";
    }



}
